﻿using System;
using System.Data;
using System.Text;
using ART.Cache;

namespace ART.Admini
{
    public partial class Master : System.Web.UI.MasterPage
    {
        private string abspath = "/admini/";
        protected void Page_Load(object sender, EventArgs e)
        {
            ART.BLL.B_TBAdmin.IsLogin();
            if (!IsPostBack)
            {
                lblSignIn.Text = BLL.B_TBAdmin.UserName;
                lblSignRole.Text = BLL.B_TBAdmin.SuperTF ? "系统管理员" : BLL.B_TBAdmin.RolesName;
                lblSignIp.Text = Common.LYRequest.GetIP();
                GetMenulist();
            }
        }

        private void GetMenulist()
        {
            object menulist = LRSCache.GetCacheService().RetrieveObject("/ws/adm/menulist/user_" + BLL.B_TBAdmin.RolesId);
            if (menulist == null) //||string.IsNullOrEmpty(menulist.ToString())
            {
                StringBuilder sb = new StringBuilder();
                DataTable dt = new BLL.B_permissions().GetList("ParentId=0 and isshow=1").Tables[0];
                int ii = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    sb.AppendFormat("<div class=\"leftmenu\"><div style=\"background:url("+abspath+"images/left_{0}.gif)\" class=\"left_title\" onClick=\"ShowItems('{1}')\">{2}</div> \n", ii.ToString().PadLeft(2, '0'), "sel_" + ii, dr["PermissName"])
                    ;
                    sb.AppendFormat("<ul class=\"left_nav\" id='{0}' style='{1}'>", "sel_" + ii, "");//(ii == 0 ? "" : "display:none;")

                    int id = Common.Utils.StrToInt(dr["id"].ToString(), 0);
                    if (id > 0 && BLL.B_TBAdmin.IsPermissions(id))
                    {
                        DataTable dt2 = new BLL.B_permissions().GetList("ParentId=" + id + " and isshow=1").Tables[0];
                        //二级
                        foreach (DataRow row in dt2.Rows)
                        {
                            sb.AppendFormat("<li><a href='{0}'>{1}</a> </li>\n", abspath+row["PageName"], row["PermissName"]);
                        }
                    }
                    sb.AppendLine(" </ul></div>");
                    ii++;
                }
                LRSCache.GetCacheService().AddObject("/ws/adm/menulist/user_" + BLL.B_TBAdmin.RolesId, sb.ToString(), 5 * 60 * 60);
                menulist = sb.ToString();

            }
            litMenu.Text = menulist.ToString();
        }
    }
}